#include "Timestamp.h"
#include <time.h>

Timestamp::Timestamp() : micSecondsSinceEpoch_(0) {}
Timestamp::Timestamp(int64_t micSecondsSinceEpoch)
    : micSecondsSinceEpoch_(micSecondsSinceEpoch) {}
// 获取当前时间戳
Timestamp Timestamp::now()
{
    return Timestamp(time(NULL));
}
// 时间格式化输出
std::string Timestamp::toString() const
{
    char buff[128] = {0};
    tm *time = localtime(&micSecondsSinceEpoch_);
    sprintf(buff, "%4d/%02d/%02d %02d:%02d:%02d",
            time->tm_year + 1900,
            time->tm_mon + 1,
            time->tm_mday,
            time->tm_hour,
            time->tm_min,
            time->tm_sec);
    return buff;
}

// #include <iostream>
// int main()
// {
//     std::cout << Timestamp::now().toString() << std::endl;
//     return 0;
// }